package com.paad.todolist;

import android.content.Context;
import java.util.*;
import android.view.*;
import android.widget.*;

public class ShoppinglistItemsAdapter extends ArrayAdapter<ShoppinglistItem> {

  int resource_id;

  public ShoppinglistItemsAdapter(Context _context, 
                             int _resource_id, 
                             List<ShoppinglistItem> _items) {
    super(_context, _resource_id, _items);
    resource_id = _resource_id;
  }

  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
    LinearLayout shoppinglistView;

    ShoppinglistItem item = getItem(position);

    String shoppinglistName = item.getName();
    //Boolean is_done = item.getDone();

    if (convertView == null) {
      shoppinglistView = new LinearLayout(getContext());
      String inflater = Context.LAYOUT_INFLATER_SERVICE;
      LayoutInflater vi = (LayoutInflater)getContext().getSystemService(inflater);
      vi.inflate(resource_id, shoppinglistView, true);
    } else {
      shoppinglistView = (LinearLayout) convertView;
    }

    //CheckBox doneView = (CheckBox)shoppinglistView.findViewById(R.id.is_done);
    TextView itemNameView = (TextView)shoppinglistView.findViewById(R.id.shoppinglist_text);
      
    //doneView.setChecked(is_done);
    itemNameView.setText(shoppinglistName);

    return shoppinglistView;
  }
}